﻿toggle = function (fsid)
{
    var div = $id("div_" + fsid);
    
        
    var display = "";
    
    if( div.style.display != "none" )
    {
        display = "none";
    }
    
    div.style.display = display;
    
}
cbkRA_c_CallbackComplete = function(e){
    if(e.parameter.startsWith("CHANGE"))
    {
        alert("Email has been changed");
        var btn = $id("btnChange");
        var load = $id("load");
        var email = $id("RA.EMAILSENDER");
        var newemail = $id("RA.NEWEMAIL");
        var resultSplitted = e.result.split(DELIMITER);
        email.value = resultSplitted[1];
        newemail.value = "";
        btn.style.display = "block";
        load.innerHTML = ""; 
    }
}
Change = function()
{
    var btn = $id("btnChange");
    var load = $id("load");
    if(confirm("save changes?"))
    {
        // di sini kirim data perubahannya
        var input = GetData();
        if(input)
        {
            btn.style.display = "none";
            load.innerHTML = "<img src='" + LOADING.src + "' alt='' />"; 
            cbkRA_c.PerformCallback(input);
        }
        else
        {
            btn.style.display = "block";
            load.innerHTML = "";
        }
    }
}
GetData = function()
{
    var output = "CHANGE" + DELIMITER;
    var iEmptyValueCount = 0;
    var newEmail = $id("RA.NEWEMAIL");
    if(newEmail.value == "")
    {
        iEmptyValueCount++;
    }
    output += newEmail.value;
    var sxError = "";
    if( iEmptyValueCount > 0 )
    {
        sxError += "terdapat field isian yang belum diisi!";
    }
    
    if( sxError != "" )
    {
        alert(sxError);
        return false;
    }
    return output;
}